#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

pushd ${DIR}/.. || exit 1

VERSION=$(cat chrome-extension/manifest.json | grep version | grep -v "manifest" | cut -d ":" -f2 | tr -d " \",")

echo "creating version v${VERSION} extension"

[[ -e chrome-releases/FlickrPhotoActionsOnThreadPages.v${VERSION}.zip ]] && echo "file exists - aborting" && exit 2

pushd chrome-extension
zip ../chrome-releases/FlickrPhotoActionsOnThreadPages.v${VERSION}.zip $(find . \( -path ./images/.svn -prune -o -path ./.svn -prune -o -path ./scripts/.svn -prune -o -print \)) || exit 3
popd

popd

echo "created FlickrPhotoActionsOnThreadPages.v${VERSION}.zip"
exit 0

